package com.agricultural.robot.model;

/**
 * 播种机 - 具体农机类型
 */
public class Planter extends AgriculturalMachine {
    private double seedDepth;

    public Planter(String name) {
        super(name);
        this.seedDepth = 5.0; // 默认播种深度(厘米)
    }

    public double getSeedDepth() {
        return seedDepth;
    }

    public void setSeedDepth(double seedDepth) {
        this.seedDepth = seedDepth;
        System.out.println(getName() + " 播种深度调整为: " + seedDepth + "厘米");
    }

    @Override
    public void performTask(Task task) {
        if (task instanceof PlantingTask) {
            PlantingTask plantingTask = (PlantingTask) task;
            System.out.println(getName() + " 开始执行播种任务: " + plantingTask.getCropType() + " 在 " + plantingTask.getFieldArea());
            System.out.println("播种深度: " + seedDepth + "厘米");
            consumeBattery(10.0);
        } else {
            System.out.println(getName() + " 无法执行该类型任务: " + task.getClass().getSimpleName());
        }
    }

    @Override
    public void update(EnvironmentData data) {
        super.update(data);
        // 根据土壤湿度调整播种深度
        if (data.getSoilMoisture() > 70) {
            setSeedDepth(seedDepth * 0.8); // 湿土减少播种深度
        } else if (data.getSoilMoisture() < 30) {
            setSeedDepth(seedDepth * 1.2); // 干土增加播种深度
        }
    }
}
